package org.ponly.cta4j.drawing.background;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

/**
 * 抽象的背景笔刷, 实现在画布上绘制背景内容.
 * <p>
 * 子类应该实现 {@link #doDrawBackground(Graphics2D, int, int)} 方法, 该方法应该完成背景的绘制工作.
 * </p>
 *
 * @author vacoor
 * @since 1.0
 */
public abstract class AbstractBackgroundBrush implements BackgroundBrush {

    /**
     * {@inheritDoc}
     */
    @Override
    public BufferedImage draw(final BufferedImage canvas) {
        final int width = canvas.getWidth();
        final int height = canvas.getHeight();
        final Graphics2D g2d = canvas.createGraphics();

        // draw background.
        doDrawBackground(g2d, width, height);

        g2d.dispose();
        return canvas;
    }

    /**
     * 使用给定的 Graphics2D 绘制背景.
     *
     * @param g2d    Graphics2D
     * @param width  画布宽度
     * @param height 画布高度
     */
    protected abstract void doDrawBackground(Graphics2D g2d, int width, int height);
}
